package com.neuedu.file;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class DataInputOutput {
	public static void main(String[] args) throws Exception{
		/*write();*/
		read();
	}

	/**
	 * 写入一些data数据
	 *  int double utf等类型
	 */
	public static void write() throws Exception {
		File file=new File("e:/data.txt");
		
		if(!file.exists()) {
			file.createNewFile();
		}
		
		//节点输出流
		FileOutputStream fos=new FileOutputStream(file);
		
		//缓存输出流
		BufferedOutputStream bos=new BufferedOutputStream(fos);
		//数据输出流
		DataOutputStream dos=new DataOutputStream(bos);
		dos.writeInt(12);
		dos.writeDouble(45.6);
		dos.writeUTF("hello");
		dos.flush();
		
		dos.close();
		bos.close();
		fos.close();
	}
	
    public static void read() throws Exception{
    	File file=new File("e:/data.txt");
    	//输入流
    	FileInputStream fis=new FileInputStream(file);
    	// 缓存输入流
    	BufferedInputStream bis=new BufferedInputStream(fis);
    	//数据输入流
    	DataInputStream dis=new DataInputStream(bis);
    	
    	System.out.println(dis.readInt());
    	System.out.println(dis.readDouble());
    	System.out.println(dis.readUTF());
    	
    	dis.close();
    	bis.close();
    	fis.close();
    	
    	
    	
	}
}
